package leducHoldem.Players;

import java.util.HashMap;
import java.util.Random;

import leducHoldem.Calculator.LeducHoldemGameTreeBuilder;
import leducHoldem.Data.Board;
import leducHoldem.Data.Move;
import leducHoldem.misc.CFRInformationSet;
import leducHoldem.misc.GameTreeManager;

public class CFRPlayer extends Player {

	private HashMap<String, CFRInformationSet> informationSets;

	public CFRPlayer(Move card, byte sign) {

		super(card, sign);

		this.informationSets = new GameTreeManager(new LeducHoldemGameTreeBuilder()).getGameTree();
	}

	@Override
	public Move getNextNode(Board situation, boolean validity) {
		Random random = new Random();
		CFRInformationSet set = informationSets.get(situation.id);

		float move = random.nextFloat();

//		System.out.println();
//		System.out.println(set);
//		System.out.println();

		for (int i = 0; i < set.getStrategy().length; i++) {
			move -= set.getStrategy()[i];

			if (move < 0) {
				return set.getMoves().get(i);
			}

		}

		return set.getMoves().getLast();
	}
	
}
